Skip to content

Conversation

zombieJ
Copy link
Member

@zombieJ zombieJ commented Sep 17, 2025

Summary by CodeRabbit

  • 新功能
    • 支持通过 getPopupClassNameFromAlign 基于对齐结果动态添加弹层 className,便于按方位定制样式;同时合并内置对齐类与自定义类,渲染更一致。
  • 测试
    • 新增用例覆盖对齐派生 className 的应用与可见性,确保弹层内容与样式正确。

Copy link

coderabbitai bot commented Sep 17, 2025

Walkthrough

本次变更在 UniqueProvider 中引入基于对齐信息的弹层 className 计算;在上下文选项中新增可选回调 getPopupClassNameFromAlign;在入口处将该回调透传到 UniqueProvider;并新增对应的单测覆盖该行为。

Changes

Cohort / File(s) 摘要
对齐类名集成(UniqueProvider)
src/UniqueProvider/index.tsx
引入 getAlignPopupClassName;通过 useMemo 基于 builtinPlacementsprefixCls 与对齐信息计算 baseClassName,并与 options.getPopupClassNameFromAlign?.(alignInfo) 合并;将结果注入 Popup 的 className
上下文选项扩展
src/context.ts
UniqueShowOptions 中新增可选属性 getPopupClassNameFromAlign?: (align: AlignType) => string
选项透传(Trigger 生成逻辑)
src/index.tsx
generateTrigger 中的 getUniqueOptions 追加透传 getPopupClassNameFromAlign 到 UniqueProvider。
测试覆盖
tests/unique.test.tsx
新增测试:验证自定义对齐派生的 className 会应用到共享 Popup,断言弹层出现且包含自定义 class 与 rc-trigger-popup-unique-controlled

Sequence Diagram(s)

sequenceDiagram
    autonumber
    actor User as 用户
    participant Trg as Trigger
    participant UP as UniqueProvider
    participant Pop as Popup

    User->>Trg: 点击目标元素
    Trg->>UP: show(options{ builtinPlacements, prefixCls, getPopupClassNameFromAlign })
    UP->>UP: 计算 alignInfo(基于触发位置)
    UP->>UP: alignedClassName = classNames( getAlignPopupClassName(...), options.getPopupClassNameFromAlign?.(alignInfo) )
    UP->>Pop: 渲染 Popup(className 包含 alignedClassName 与 options.popupClassName)
    Note over Pop: 弹层展示并带有对齐相关类名
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • afc163

Poem

小兔抖抖耳,轻点云边屏,
对齐生新衣,类名贴得紧。
一缕风掠过,Popup亮晶晶,
测试来作证,跳跃到天庭。
啪嗒啪——样式对齐,万事咬合赢。 🐇✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed 标题 “fix: unique popup missing className” 简洁且直接反映了本次变更的核心:为 UniqueProvider 的弹出层补回/注入缺失的基于对齐(align)计算的 className(通过新增 getPopupClassNameFromAlign、计算 alignedClassName 并将其并入 Popup 的 className)。该标题与文件改动和新增测试一致,便于阅读变更历史。
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix-popup

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 48ac48e and 008c930.

📒 Files selected for processing (4)
  • src/UniqueProvider/index.tsx (3 hunks)
  • src/context.ts (1 hunks)
  • src/index.tsx (1 hunks)
  • tests/unique.test.tsx (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (3)
tests/unique.test.tsx (1)
tests/util.tsx (1)
  • awaitFakeTimer (97-104)
src/context.ts (1)
src/interface.ts (1)
  • AlignType (23-89)
src/UniqueProvider/index.tsx (1)
src/util.ts (1)
  • getAlignPopupClassName (17-37)
🔇 Additional comments (9)
src/context.ts (1)

34-34: 新增可选属性的类型定义符合预期

这个新增的 getPopupClassNameFromAlign 属性定义合理,类型为 (align: AlignType) => string,允许根据对齐信息动态生成类名。该属性设计为可选,保持了向后兼容性。

src/index.tsx (4)

102-102: 新增属性与上下文保持一致

TriggerProps 接口中新增的 getPopupClassNameFromAlign 属性与 UniqueShowOptions 中的定义保持一致,为用户提供了通过对齐信息自定义类名的能力。


179-179: 参数解构位置合适

getPopupClassNameFromAlign 解构放在与弹窗相关的其他属性附近,代码组织清晰。


334-334: 正确传递属性到 UniqueProvider

getUniqueOptions 中正确包含了 getPopupClassNameFromAlign 属性,确保该功能在 UniqueProvider 中可用。


494-509: 对齐类名的计算逻辑设计合理

使用 React.useMemo 缓存计算结果是正确的优化。逻辑分为两步:先通过 getAlignPopupClassName 获取基础类名,再通过用户提供的回调函数扩展类名,设计清晰。依赖数组完整包含了所有相关变量。

tests/unique.test.tsx (1)

107-157: 测试用例设计全面且合理

测试用例很好地验证了新功能的正确性:

  1. 定义了自定义的 getPopupClassNameFromAlign 函数
  2. 配置了 builtinPlacements 用于对齐
  3. 验证了弹窗显示后包含预期的自定义类名
  4. 包含了对异步对齐的考虑

测试覆盖了关键功能点,确保新增的对齐类名功能能正常工作。

src/UniqueProvider/index.tsx (3)

18-18: 导入必要的工具函数

正确导入了 getAlignPopupClassName 工具函数,用于计算基础对齐类名。


97-115: 对齐类名计算的实现设计优秀

这段代码的实现很好:

  1. 使用 useMemo 进行性能优化
  2. 适当的空值检查避免运行时错误
  3. 将基础类名与用户自定义类名合并的逻辑清晰
  4. 依赖数组完整且准确
  5. 硬编码 alignPointfalse 符合 UniqueProvider 的使用场景

代码质量高,逻辑正确。


165-165: 正确应用计算后的类名

Popup 组件的 className 属性中正确使用了计算得出的 alignedClassName,与现有的 popupClassName 和控制类名一起应用,集成自然。


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary of Changes

Hello @zombieJ, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request resolves a styling issue within the UniqueProvider component where popups were failing to receive dynamically generated class names based on their alignment. The changes introduce a mechanism to correctly apply these alignment-specific class names, improving the visual consistency and behavior of popups. Additionally, a new prop is provided for greater customization of popup class names based on alignment.

Highlights

  • Missing Class Name Fix: The pull request addresses an issue where the UniqueProvider's popup was not correctly applying alignment-related class names, leading to potential styling inconsistencies.
  • Dynamic Class Name Generation: New logic has been introduced within UniqueProvider to dynamically compute class names based on the popup's alignment information, utilizing the getAlignPopupClassName utility.
  • Customizable Alignment Class Names: A new prop, getPopupClassNameFromAlign, has been added to UniqueShowOptions, allowing developers to provide a custom function to generate additional class names based on the popup's alignment.
  • Enhanced Test Coverage: A new test case has been added to tests/unique.test.tsx to verify that the getPopupClassNameFromAlign prop correctly applies custom class names to the UniqueProvider's popup, ensuring the fix works as expected.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

codecov bot commented Sep 17, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.86%. Comparing base (48ac48e) to head (008c930).

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #570      +/-   ##
==========================================
+ Coverage   95.83%   95.86%   +0.03%     
==========================================
  Files          18       18              
  Lines         937      944       +7     
  Branches      273      276       +3     
==========================================
+ Hits          898      905       +7     
  Misses         39       39              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request fixes an issue where a unique popup was missing a className. The changes involve adding a getPopupClassNameFromAlign prop and using it within UniqueProvider to compute and apply the correct aligned class name. A new test case is also added to verify this functionality. The implementation is mostly correct, but I've suggested a small refactoring in UniqueProvider/index.tsx to improve the usage of the useMemo hook for better maintainability and adherence to React best practices.

Comment on lines +97 to +115
const alignedClassName = React.useMemo(() => {
if (!options) {
return '';
}

const baseClassName = getAlignPopupClassName(
options.builtinPlacements || {},
options.prefixCls || '',
alignInfo,
false, // alignPoint is false for UniqueProvider
);

return classNames(baseClassName, options.getPopupClassNameFromAlign?.(alignInfo));
}, [
alignInfo,
options?.getPopupClassNameFromAlign,
options?.builtinPlacements,
options?.prefixCls,
]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The dependency array for React.useMemo uses optional chaining (options?.prop), which is an anti-pattern and can lead to incorrect memoization behavior. The exhaustive-deps lint rule would likely flag this. It's better to depend on the options object directly and destructure the needed properties inside the memoized function. This makes the dependencies clearer and ensures the memoization works as expected when the options object itself changes.

  const alignedClassName = React.useMemo(() => {
    if (!options) {
      return '';
    }

    const { builtinPlacements, prefixCls, getPopupClassNameFromAlign } = options;

    const baseClassName = getAlignPopupClassName(
      builtinPlacements || {},
      prefixCls || '',
      alignInfo,
      false, // alignPoint is false for UniqueProvider
    );

    return classNames(baseClassName, getPopupClassNameFromAlign?.(alignInfo));
  }, [alignInfo, options]);

@zombieJ zombieJ merged commit d394943 into master Sep 17, 2025
9 of 10 checks passed
@zombieJ zombieJ deleted the fix-popup branch September 17, 2025 09:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant